package performace_test;

import java.util.Random;

import unionFound.CandyUnionFind;
import unionFound.CandyUnionFindImpl_v3;
import unionFound.CandyUnionFindImpl_v4;
import unionFound.CandyUnionFindImpl_v5;
import unionFound.CandyUnionFindImpl_v6;

/**
 * 
 * @Title: UnionFindPerformaceTest.java 
 * @Package performace_test 
 * @Description: 比较不同并查集的性能
 * @author CandyWall   
 * @date 2021年1月11日 下午12:10:53 
 * @version V1.0
 */
public class UnionFindPerformaceTest {
    public static double testUnionFind(CandyUnionFind unionFind, int opCount) {
        int size = unionFind.getSize();
        Random random = new Random();
        long start = System.nanoTime();
        for(int i = 0; i < opCount; i++) {
            int a = random.nextInt(size);
            int b = random.nextInt(size);
            unionFind.unionElements(a, b);
        }
        for(int i = 0; i < opCount; i++) {
            int a = random.nextInt(size);
            int b = random.nextInt(size);
            unionFind.isConnected(a, b);
        }
        return (System.nanoTime() - start) / 1000_000_000.0;
    }
    
    public static void main(String[] args) {
        int opCount = 1000_0000;
        int size = 1000_000;
        /*int opCount = 100000;
        int size = 100000;
        double cost1 = testUnionFind(new CandyUnionFindImpl_v1(size), opCount);
        System.out.println("CandyUnionFindImpl_v1耗时：" + cost1 + " 秒");
        double cost2 = testUnionFind(new CandyUnionFindImpl_v2(size), opCount);
        System.out.println("CandyUnionFindImpl_v2耗时：" + cost2 + " 秒");*/
        double cost3 = testUnionFind(new CandyUnionFindImpl_v3(size), opCount);
        System.out.println("CandyUnionFindImpl_v3耗时：" + cost3 + " 秒");
        double cost4 = testUnionFind(new CandyUnionFindImpl_v4(size), opCount);
        System.out.println("CandyUnionFindImpl_v4耗时：" + cost4 + " 秒");
        double cost5 = testUnionFind(new CandyUnionFindImpl_v5(size), opCount);
        System.out.println("CandyUnionFindImpl_v5耗时：" + cost5 + " 秒");
        double cost6 = testUnionFind(new CandyUnionFindImpl_v6(size), opCount);
        System.out.println("CandyUnionFindImpl_v6耗时：" + cost6 + " 秒");
    }
}
